<?php
// +----------------------------------------------------------------------+
// | Author:  Evgeny Leontev <eleontev@gmail.com>                         |
// | Copyright (c) 2005 Evgeny Leontev                                    |
// +----------------------------------------------------------------------+
// | This source file is free software; you can redistribute it and/or    |
// | modify it under the terms of the GNU Lesser General Public           |
// | License as published by the Free Software Foundation; either         |
// | version 2.1 of the License, or (at your option) any later version.   |
// |                                                                      |
// | This source file is distributed in the hope that it will be useful,  |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    |
// | Lesser General Public License for more details.                      |
// +----------------------------------------------------------------------+

class Auth extends AppModel
{

	var $sql;
	
	
	//function Auth() {
		
	//}
	
	
	function setTable($table) {
		$this->tbl->table = $table;
	}	
	
	function setSql($sql) {
		$this->sql = $sql;
	}


	function authToSession($name, $user_id, $realname, $username, $role_id = false) {
		$_SESSION[$name]['auth'] = md5(session_id() . $username . Auth::getIP());
		$_SESSION[$name]['thua'] = session_id();
		$_SESSION[$name]['user_id'] = $user_id; 	// for chekPriv();
		$_SESSION[$name]['username'] = $username;
		$_SESSION[$name]['realname'] = $realname;
		$_SESSION[$name]['role_id'] = $role_id;
		$_SESSION[$name]['time_flag'] = time(); 		// time when entering admin area using in spentTime();
	}
	
	
	// period - 1 hour, 5 days, 8 months, 2 years ...
	function getCookieTime($period = false, $sign = '+') {
		return ($period) ? strtotime($sign . $period) : time();
	}

	
	function setCookieExpire($period = false) {
		$this->cookie_expire = $this->getCookieTime($period);
	}
	
	
	function removeCookie() {
		$this->authToCookie();
	}

	
	function getIP() {
		//return WebUtil::getIP();
		return '';
	}
	
	
	// priv replacements
	function isPriv() {
		return true;
	}
	
	function checkPrivAction() {
		return true;
	}	
}
?>
